from flask import Flask
from urllib.parse import quote_plus as urlquote
from waitress import serve
import models, routes
import pymysql
from config.config import *

pymysql.install_as_MySQLdb()

# flask & SQLALCHEMY
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "{}://{}:{}@{}:{}/{}?charset=utf8" \
    .format('mysql', MYSQL_USER, urlquote(MYSQL_PASSWORD), MYSQL_HOST, MYSQL_PORT, MYSQL_DBNAME)
app.config['POOL_SIZE'] = 50
app.config['SQLALCHEMY_ECHO'] = False
app.config['SQLALCHEMY_POOL_TIMEOUT'] = 800
app.config['MAX_OVERFLOW'] = 20
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_POOL_RECYCLE'] = 800

models.init_app(app)
routes.init_app(app)

if __name__ == '__main__':
    serve(app, host="0.0.0.0", port=5000)
